#include "HardwareProfile.h"
#include "afx.h"
#include "TypeDefine.h"
void __delay_20ms(unsigned int x)
{
	while(x--)
	{
		__delay_ms(20);
	}
}
unsigned long Long2BCD(unsigned long l)
{
	ulong ret;
	unsigned char x;
	if(l>99999999)
		return 0;
	x=l/10000000;//8
	ret.u8s[3]=HIGH_NIBBLE(x);
	l=l-x*10000000;
	x=l/1000000;//7
	ret.u8s[3]=LOW_NIBBLE(x);
	l=l-x*1000000;
	x=l/100000;//6
	ret.u8s[2]=HIGH_NIBBLE(x);
	l=l-x*100000;
	x=l/10000;//5
	ret.u8s[2]=LOW_NIBBLE(x);
	l=l-x*10000;
	x=l/1000;//4
	ret.u8s[1]=HIGH_NIBBLE(x);
	l=l-x*1000;
	x=l/100;//3
	ret.u8s[1]=LOW_NIBBLE(x);
	l=l-x*100;
	x=l/10;//2
	ret.u8s[0]=HIGH_NIBBLE(x);
	l=l-x*10;
	//x=l/10000;//1
	ret.u8s[0]=LOW_NIBBLE(x);
	return ret.u32;
}
void Byte2ASCII(unsigned char b, unsigned char *h, unsigned char *l)
{
	//h=(unsigned char)h;
	//l=(unsigned char)l;
	*h = HIGH_NIBBLE(b);
	*l = LOW_NIBBLE(b);
	if (*h > 9)
		*h = *h - 0x0a + 'A';
	else
		*h = *h + '0';
	if (*l > 9)
		*l = *l - 0x0a + 'A';
	else
		*l = *l + '0';
}
unsigned char ASCII2Byte(unsigned char h,unsigned char l)
{
	if(h>'9')
		h=h-55;//-'A'+10;
	else
		h=h-'0';
	if(l>'9')
		l=l-55;//-'A'+10;
	else
		l=l-'0';
	return MAKE_BYTE(h,l);
}
